var yuecaiKangjunyaowu = new Vue({
    el : "#yuecaiKangjunyaowulist",
    data :{
        xiangmuId : $("#xiangmuId").val(),
        xiangmu : {},
        kangjunyaowu :{},
        kangjunyaowulist : [],
        show : true,					// 显示列表是否有数据

        pageIndex : 1,
        pageSize :20,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",

    },

    created : function() {
        var _this = this;
        xiangmuId=_this.xiangmuId;
        _this.bindKangjunyaowuList();
        _this.bindXiangmu();

    },
    methods : {
        toback : function() {
            window.history.go(-1);
        },
        bindXiangmu:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid : _this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toDelete:function (){
            var _this = this;

            layer.confirm("确定删除该项目的材料吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/yuecaikangjunyaowu/delete", {
                    xiangmuid : _this.xiangmuId,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"删除成功!",
                            });

                            _this.bindKangjunyaowuList();
                            _this.bindXiangmu();
                        }
                    }
                },"json");
            })
        },

        bindKangjunyaowuList:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/yuecaikangjunyaowu/findyuecaikangjunyaowulist",{
                xiangmuid : _this.xiangmuId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >序号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >药品名称</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >医保</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >院本部药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >秦淮药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >药品类别</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >抗菌药物小组会预选意见（得票数/总票数）</th>\n" +
                           /* "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >申请科室</th>\n" +*/
                            "       <th style=\"text-align:center;vertical-align:middle;width:200px;\" >国家平台备注信息</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >规格1</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >规格2</th>\n" +

                            "    </thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";
                        if(data.YuecaikangjunyaowuList.length>0){

                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.YuecaikangjunyaowuList.length; i++) {
                                var mmYuecaiOne = data.YuecaikangjunyaowuList[i];

                                var mmpaixuhao = mmYuecaiOne.ordernumber;
                                var mmyaowumingcheng = mmYuecaiOne.yaopinmingcheng;
                                var mmyibao = mmYuecaiOne.yibao;
                                var mmyuanbenbuyao = mmYuecaiOne.yuanbenbuyao;
                                var mmqinhuaiyao = mmYuecaiOne.qinhuaiyao;
                                var mmnanjingchuangxin = mmYuecaiOne.nanjingchuangxin;
                               /* var mmzhuankefenzu = mmYuecaiOne.zhuankefenzu;
                                var mmshenqingkeshi = mmYuecaiOne.shenqingkeshi;*/
                                var mmbeizhu = mmYuecaiOne.beizhu;
                                var mmbeizhu2 = mmYuecaiOne.beizhu2;
                                var mmbeizhu3 = mmYuecaiOne.beizhu3;
                                var mmbeizhu4 = mmYuecaiOne.beizhu4;


                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmpaixuhao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmyaowumingcheng + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmyibao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmyuanbenbuyao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmqinhuaiyao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmnanjingchuangxin + "</td>";
                              /*  mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmzhuankefenzu + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmshenqingkeshi + "</td>";*/
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmbeizhu4 + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:200px;white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden; text-align: left'><a title='" + mmbeizhu + "'>" + mmbeizhu + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmbeizhu2 + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmbeizhu3 + "</td>";


                                mmHtml += "</tr>";

                            }
                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },

    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.bindKangjunyaowuList();
        }
    }
});
